package org.stwy.lease.quit;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.stwy.lease.returnmoney.ReturnEntity;
import org.stwy.lease.returnmoney.ReturnService;

import com.rap.common.persistence.IBaseDAO;
import com.rap.common.exception.ServiceException;
import com.rap.common.service.BaseServiceImpl;

/**
 * 退租 服务类
 */
/**
*版权信息 (c) RAP 保留所有权利.
*@author Rap.Codegen
*@Team RAP Team
*@Date 2015-4-19 22:11:54
*<p></p>
*
*@参与人：Rap.Codegen
*/
 
@Service
@Transactional(rollbackFor=Exception.class)
public class QuitService extends BaseServiceImpl<QuitEntity, String> {

	@Autowired
	private QuitDAO dao;
	@Autowired
	ReturnService returnService;
	@Override
	protected IBaseDAO getDAO() {
		return dao;
	}
	/**
	 * 退款
	 * @param pks
	 * @param returnDate
	 * @param remark
	 * @param returnRent
	 * @param returnDeposit
	 * @throws ServiceException
	 */
	public void doReturnMoney(String[] pks, Date returnDate, String remark,
			Double returnRent, Double returnDeposit) throws ServiceException  {
		for(String pk: pks){
			QuitEntity quit = this.get(pk);
			ReturnEntity r = new ReturnEntity();
			r.setQuit(quit);
			r.setRemark(remark);
			r.setReturnDate(returnDate);
			r.setReturnDeposit(returnDeposit);
			r.setReturnRent(returnRent);
			r.setStatus(1);
			returnService.save(r);
			quit.setIsReturn(true);
			this.save(quit);
		}
	}
}
